package edu.sctu.zhu.weixing;

import com.google.gson.Gson;
import edu.sctu.zhu.util.HttpClientUtil;
import edu.sctu.zhu.weixing.bean.AccessToken;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by zhu on 2016/5/4.
 */
public class AccessTokenUtil {
    public static String access_token="";
    private static final Timer timer = new Timer();
    public static void refresh(){
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                String result = HttpClientUtil.doGetSSL("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx6fd8fa52f64296ef&secret=9b36650f00088a17b7baa8b722e12a72");
                Gson gson = new Gson();
                AccessToken accessToken = gson.fromJson(result, AccessToken.class);
                access_token = accessToken.getAccess_token();
                System.out.println(access_token);
            }
        },0,3600*90);

    }
}
